-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Mcap typescript flatbuffer encoding example #726
Conversation
export function buildGridMessage(builder: Builder, json: Grid): number { | ||
const frameId = builder.createString(json.frame_id); | ||
|
||
const pose = buildPose(builder, json.pose); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a curiosity question: what is the builder itself for? It seems like the actual objects are created by calling startX...endX. Is the builder storing some shared state? Does the builder actually need to be passed in or could this function create its own builder?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The builder as far as I cant tell allows for abstracted use of the underlying buffer, expansion of buffer and tracks how much of it is allocated. So when you start a new object on the buffer and add attributes to it it allocates a given space for it in the continuous chunk and tracks where the next object can begin. It also allows the buffer to have a root
schema, hence the importance of ending the buffer with the main message type. All of the fields and data in a message have to be in the same buffer so when you create/end a Quaternion
the index of that quaternion needs to be used when adding it to the object of the schema that includes it so that it can reference it in the same buffer.
function roundUp(numToRound: number, multiple: number) { | ||
if (multiple !== 0 && (multiple & (multiple - 1)) === 0) { | ||
return (numToRound + multiple - 1) & -multiple; | ||
} else { | ||
throw Error(`invalid multiple ${multiple}, num to round ${numToRound}`); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe just use lodash round() or something like that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just simplified this code. Not sure if there's a lodash equivalent. It's not strictly necessary but nice to have
Co-authored-by: Jacob Bandes-Storch <jacob@foxglove.dev>
Added an example showing how to create an mcap file using flatbuffers encoding in typescript
schemas (not dependent, but uses output from compiling the added schemas) PR: Add Flatbuffer Schema Support schemas#70